package day5.exe;

public class Company {
    String name;
    String address;
    String number;
    String sell;
    int index = 0;
    Staff[] staff = new Staff[100];

    public void add(String sname, String age, String sex, String post, String salary) {
        if (index >= staff.length) {
            System.out.println("员工已经招满了！");
            return;
        }
        for (int i = 0; i < index; i++) {
            if (staff[i].sname.equals(name)) {
                System.out.println("姓名有了");
                return;
            }
            //!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            staff[index] = new Staff(name, age, sex, post, salary);
//            staff[index].sname = name;
//            staff[index].age = age;
//            staff[index].sex = sex;
//            staff[index].post = post;
//            staff[index].salary = salary;
            index++;
        }
        System.out.println("已招聘为新员工");
    }

    public void showSta() {
        for (int i = 0; i < index; i++) {
            System.out.println("员工姓名：" + staff[i].sname + "\t年龄" + staff[i].age + "\t性别" + staff[i].sex + "\t职务" + staff[i].post + "\t薪水" + staff[i].salary);
        }
    }

    public void showinfo() {
        System.out.println("公司名称是：" + name + "有限公司");
        System.out.println("公司的地址是：" + address);
        System.out.println("公司的电话是：" + number);
        System.out.println("公司的经营范围是：" + sell);
        System.out.println("员工信息如下：");
        for (int i = 0; i < index; i++) {
            System.out.print(staff[i].sname + "\t" + staff[i].age);
        }
    }

    public void delete(String name) {
        for (int i = 0; i < index; i++) {
            if (staff[i].sname.equals(name)) {
                int j = i;
                for (; j < index - 1; j++) {
                    staff[j].sname = staff[j + 1].sname;
                    staff[j].age = staff[j + 1].age;
                    staff[j].sex = staff[j + 1].sex;
                    staff[j].post = staff[j + 1].post;
                    staff[j].salary = staff[j + 1].salary;
                }
                staff[j] = null;
                index--;
                System.out.println("辞退成功");
                return;
            }
        }
        System.out.println("公司没有此员工");
    }

    public int number() {
        return index;
    }
}